<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %><%--
  Created by IntelliJ IDEA.
  User: A
  Date: 2024/4/8
  Time: 14:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <style>
        .chart-container {
            display: flex;
            justify-content: space-between;
            flex-wrap: wrap;
            margin-bottom: -20px; /* 减少两个图表之间的垂直间距 */
        }
        .chart-item {
            width: 48%; /* 设置每个图表占据的宽度 */
            margin-bottom: 20px; /* 设置图表之间的垂直间距 */
        }
        .centered-chart {
            text-align: center; /* 图表居中显示 */
        }
    </style>
</head>
<body>
    <!-- 为 ECharts 准备一个定义了宽高的 DOM -->
    <div class="chart-container">
        <div id="main1" class="chart-item" style="height: 400px;"></div>
        <div id="main2" class="chart-item" style="height: 400px;"></div>
    </div>

    <div class="centered-chart">
        <div id="main3" style="width: 600px; height: 400px;"></div>
    </div>

    <script src="../../static/echarts.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../static/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>

    <script type="text/javascript">
        // 基于准备好的dom，初始化echarts实例
        var myChart1 = echarts.init(document.getElementById('main1'));
        var myChart2 = echarts.init(document.getElementById('main2'));
        var myChart3 = echarts.init(document.getElementById('main3'));
        $.post(
            '/echarts?method=selectBrandCount',
            function (jsonObj) {
                console.log(jsonObj);

                var xArray = new Array();
                var yArray = new Array();
                for (var BrandCountVO of jsonObj) {
                    xArray.push(BrandCountVO.name);
                    yArray.push(BrandCountVO.value);
                }
                // 指定图表的配置项和数据
                var option1 = {
                    title: {
                        text: 'ECharts 入门示例'
                    },
                    tooltip: {},
                    legend: {
                        data: ['销量']
                    },
                    xAxis: {
                        data: xArray
                    },
                    yAxis: {},
                    series: [
                        {
                            name: '销量',
                            type: 'bar',
                            data: yArray
                        }
                    ]
                };
                // 使用刚指定的配置项和数据显示图表。
                myChart1.setOption(option1);

                var option2 = {
                    title: {
                        text: 'Referer of a Website',
                        subtext: 'Fake Data',
                        left: 'center'
                    },
                    tooltip: {
                        trigger: 'item'
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left'
                    },
                    series: [
                        {
                            name: 'Access From',
                            type: 'pie',
                            radius: '50%',
                            data: jsonObj,
                            emphasis: {
                                itemStyle: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };

                myChart2.setOption(option2);

                var option3 = {
                    tooltip: {
                        trigger: 'item'
                    },
                    legend: {
                        top: '5%',
                        left: 'center'
                    },
                    series: [
                        {
                            name: 'Access From',
                            type: 'pie',
                            radius: ['40%', '70%'],
                            avoidLabelOverlap: false,
                            itemStyle: {
                                borderRadius: 10,
                                borderColor: '#fff',
                                borderWidth: 2
                            },
                            label: {
                                show: false,
                                position: 'center'
                            },
                            emphasis: {
                                label: {
                                    show: true,
                                    fontSize: 40,
                                    fontWeight: 'bold'
                                }
                            },
                            labelLine: {
                                show: false
                            },
                            data: jsonObj
                        }
                    ]
                };
                myChart3.setOption(option3);

            },
            'json'
        )


    </script>
</body>
</html>
